﻿<%@ Page Title="公司资料" Language="C#" MasterPageFile="~/master/m.master" %>
<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
<link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
<style type="text/css">
.system-box .right-side{width: 100%;}
.condition, .condition-title{border-bottom: 1px solid #dfdfdd;}
.condition .form-control{padding: 2px 6px;}

.module-info td .control-label {
    margin-right: 0px;
    width: 70px;
}
</style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
    <div class="system-box">
	<div class="right-side">
		<div class="btns-container">
            <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true">
		    	<form id="checkModuleForm" method="get" action="#">
					<div class="modal-dialog">
		        		<div class="modal-content animated bounceInRight">
		            		<div class="modal-header">
		                    	<span class="editTitle"></span>
		                    	<button type="button" class="close" data-dismiss="modal">
		                    		<span aria-hidden="true">&times;</span>
		                        	<span class="sr-only">关闭</span>
		                        </button>
		                    </div>
		                    <div id="message" style="display: none"></div>
		                    <div class="modal-body">
		                    	<table class="module-info" cellpadding="0" cellspacing="0">
		                        	<thead></thead>
		                        	<tbody>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">公司名称</label>
													<input type="text" id="CompanyName" name="CompanyName" placeholder="请输入公司名称" 
                                                        datacol="yes" err="公司名称" checkexpession="NotNull" maxlength="100" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                         <tr>
											<td>
												<div class="form-group">
													<label class="control-label">公司简称</label>
													<input type="text" id="CompanyShortName" name="CompanyShortName" placeholder="请输入公司简称" 
                                                        datacol="yes" err="公司简称" checkexpession="NotNull" maxlength="50" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">税号</label>
													<input type="text" id="TaxNumber" name="TaxNumber" placeholder="请输入税号" 
                                                        datacol="yes" err="税号" checkexpession="NotNull" maxlength="20" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">开户行</label>
													<input type="text" id="BankName" name="BankName" placeholder="请输入开户行" 
                                                        datacol="yes" err="开户行" checkexpession="NotNull" maxlength="30" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">帐号</label>
													<input type="text" id="AccountCode" name="AccountCode" placeholder="请输入帐号" 
                                                        datacol="yes" err="帐号" checkexpession="NotNull" maxlength="20" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">联系电话</label>
													<input type="text" id="Telephone" name="Telephone" placeholder="请输入联系电话" 
                                                        datacol="yes" err="联系电话" checkexpession="NotNull" maxlength="13" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
											<td>
												<div class="form-group">
													<label class="control-label">公司地址</label>
													<input type="text" id="CompanyAddress" name="CompanyAddress" placeholder="请输入公司地址" 
                                                        datacol="yes" err="公司地址" checkexpession="NotNull" maxlength="100" 
                                                        class="form-control input-w490 required" style="display: none;" autocomplete="off" />
												</div>
											</td>
										</tr>
                                        <tr>
                                            <td>
                                                 <div class="form-group">
                                            	<label class="control-label">品牌</label>
                                                         <div class="checkbox i-checks label-inline">
	                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
		                        	</tbody>
		                    	</table>
		                	</div>
		                	<div class="modal-footer">
		                    	<button type="button" id="addModuleBtn" class="btn btn-primary">保存</button>
		                    	<button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button>
		                    </div>
		                </div>
		            </div>
		        </form>
		    </div>
		</div>
		 <div class="condition">
            <label>公司名称</label>
            <input class="form-control input-w155" id="search-Name" placeholder="输入公司名称或简称"/>

        </div>
        <div class="right-content-box">
			<div class="ibox-content">
				<table class="footable table table-stripped table-list loadTable">
					<thead></thead>
					<tbody id="pageList"></tbody>
				</table>
			</div>
		</div>
        <div class="pageControl"></div>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
    <script src="../assets/img/validate/learunui-validator.js"></script>
<script src="../assets/js/page/pageControl.js"></script>
<script src="../assets/js/page/rScroll.js"></script>
<script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
<script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
<script src="../assets/js/framework.js"></script>
<script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>

<script>
  

    $('document').ready(function () {
        commonUtil.bindDict3({ DictValue: 'Brand' }, '.i-checks');
            $(".i-checks").iCheck({
                checkboxClass: "icheckbox_square-green",
            });
        //模块ID
        var ModuleID = Y.getUrlParam("ModuleID");
        //当前页数
        var page = 1;
        commonUtil.loadBtnList(ModuleID, function () {
            $('#editBtn').attr("disabled", "disabled");
            rScroll();
        });
        var _CompanyID = null;
        var _CompanyName = null;
        var _CompanyShortName = null;
        var _TaxNumber = null;
        var _BankName = null;
        var _AccountCode = null;
        var _Telephone = null;
        var _CompanyAddress = null;
        var _Brand = null;

     
        //处理表头
        if ($('.footable thead').children().size() == 0) {
            tableControl.initThead('.footable',
            [
                {
                    trClass: '',
                    children: [
                        //{ tdText: '公司代码', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '公司名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '公司简称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '税号', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '详细地址', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '开户行', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '账号', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '联系电话', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                         { tdText: '品牌', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                        { tdText: '操作员', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                    ]
                }
            ]);
        }

        var pageList = [];
        var loadList = function () {
            pageControl.init('CsrdCompany', 'GetList', {
                SearchStr: $('#search-Name').val(),
                Page: page,
                Size: 100,
                needLayer: true,
                alwaysCallBack: function () {
                    $('#pageList').empty();
                }
            }, function (result) {
                pageList = [];
                page = result.page;
                var tBody = [];
                if (!Y.checkNull(result.data)) {
                    if (result.data.Items.length > 0) {
                        result.data.Items.map(function (item, i) {
                            pageList.push(item);

                           // console.log(item.PopularRate);

                            var tempTr = {
                                trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                children: [
                                    { tdText: (item.CompanyID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide CompanyID' },
                                    { tdText: (item.CompanyName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'CompanyName' },
                                    { tdText: (item.CompanyShortName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'CompanyShortName' },
                                    { tdText: (item.TaxNumber || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'TaxNumber' },
                                    { tdText: (item.CompanyAddress || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'CompanyAddress' },
                                    { tdText: (item.BankName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'BankName' },
                                    { tdText: (item.AccountCode || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'AccountCode' },
                                    { tdText: (item.Telephone || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Telephone' },
                                    { tdText: (item.Brand || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Brand' },
                                    { tdText: (item.Operator || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Operator' }
                                
                                ]
                            };
                            tBody.push(tempTr);
                        });
                    }
                    rScroll();
                }
                tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);

                _CompanyID = "";
                _CompanyName = "";
                _CompanyShortName = "";
                _TaxNumber = "";
                _BankName = "";
                _AccountCode = "";
                _Telephone = "";
                _CompanyAddress = "";
                _Brand = "";
                $('#editBtn').attr('disabled', 'disabled');
                $('#deleteBtn').attr('disabled', 'disabled');
            });
        }
        loadList();

        //选中记录
        $('#pageList').on('click', 'tr', function () {
            _CompanyID = $(this).find('.CompanyID').text();
            _CompanyName = $(this).find('.CompanyName').text();
            _CompanyShortName = $(this).find('.CompanyShortName').text();
            _TaxNumber = $(this).find('.TaxNumber').text();
            _BankName = $(this).find('.BankName').text();
            _AccountCode = $(this).find('.AccountCode').text();
            _Telephone = $(this).find('.Telephone').text();
            _CompanyAddress = $(this).find('.CompanyAddress').text();
            _Brand = $(this).find('.Brand').text();
            if (!Y.checkNull(_CompanyID)) {
                $('#editBtn').removeAttr('disabled');
                $('#deleteBtn').removeAttr('disabled');
            }
            $('.footable tr').removeClass('check');
            $("input[type='checkbox']:checkbox")
               .each(function () {
                   //if (true == $(this).is(':checked')) {
                       $(this).iCheck('uncheck');
                  // }
               });
        });

        //查询按钮
        $('.btns-container').on('click', '#btn-search', function () {
            page = 1;
            loadList();
        });
        //删除
        commonUtil.initDeleteBtnEvent({
            callBack: function () {
                Y.API2('CsrdCompany', 'Remove', { CompanyID: _CompanyID }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal('删除失败', data.Message, 'error');
                    } else {
                        swal('删除成功', '该信息已被你永久删除', 'success');
                        //刷新列表
                        loadList();
                    }
                });
            }
        });
        
        //新增按钮
        $('.btns-container').on('click', '#addBtn', function () {
            $('.editTitle').text('新增配置');
            _isCreat = true;
            $('#CompanyName').val("");
            $('#CompanyShortName').val("");
            $('#TaxNumber').val("");
            $('#BankName').val("");
            $('#AccountCode').val("");
            $('#Telephone').val("");
            $('#CompanyAddress').val("");
            $("input[type='checkbox']:checkbox")
             .each(function () {
                 //if (true == $(this).is(':checked')) {
                 $(this).iCheck('uncheck');
                 // }
             });
        });

        //编辑按钮
        $('.btns-container').on('click', '#editBtn', function () {
            $('.editTitle').text('编辑配置');
            _isCreat = false;
	    
            $('#CompanyName').val(_CompanyName);
            $('#CompanyShortName').val(_CompanyShortName);
            $('#TaxNumber').val(_TaxNumber);
            $('#BankName').val(_BankName);
            $('#AccountCode').val(_AccountCode);
            $('#Telephone').val(_Telephone);
            $('#CompanyAddress').val(_CompanyAddress);
            if (!Y.checkNull(_Brand)) {
                var s = _Brand.split(',');
                $("input[type='checkbox']").each(function (j) {
                    s.map(function(r,i) {
                        if (r == $($("input[type='checkbox']")[j]).val()) {
                            $($("input[type='checkbox']")[j]).iCheck('check');
                        } 
                    });
                    
                });
            }
        });

        //保存操作
        $('#addModuleBtn').click(function () {
            var str="";
            $("input[type='checkbox']:checkbox").each(function () {
                if (true == $(this).is(':checked')) {
                    str += $(this).val() + ",";
                }
            });
           
            if (!CheckDataValid('#checkModuleForm')) {
                return false;
            }
            if (str == "") {
                tipCss($(".i-checks"), '请选择品牌');
                return false;
            }
         
            var action = "";
            var successText = "";
            if (_isCreat) {
                action = "Create";
                successText = '新增成功';
            } else {
                action = "Modify";
                successText = '编辑成功';
            }

            layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
            Y.API2('CsrdCompany', action,
                {
                    CompanyID: _CompanyID,
                    CompanyName: $('#CompanyName').val(),
                    CompanyShortName: $("#CompanyShortName").val(),
                    TaxNumber: $("#TaxNumber").val(),
                    BankName: $("#BankName").val(),
                    AccountCode: $("#AccountCode").val(),
                    Telephone: $("#Telephone").val(),
                    CompanyAddress: $("#CompanyAddress").val(),
                    Brand:str
                },
                function(data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框
                        $('#closeAddBox').click();
                        //刷新列表
                        loadList();
                    }
                });
        });

        //$('#addWindow').on('shown.bs.modal', function () {
        //    $(".chosen-select").chosen();
        //    $('.chosen-select').trigger('chosen:updated');
        //});
   
    });
    
</script>
</asp:Content>

